package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.ApplicationKeyValue;
import com.oocl.euc.core.maintenance.repository.ApplicationKeyValueRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ApplicationKeyValueBuilder {

    private ApplicationKeyValue applicationKeyValue;

    @Autowired
    private ApplicationKeyValueRepository applicationKeyValueRepository;

    public ApplicationKeyValueBuilder defaultBuilder() {
        this.applicationKeyValue = new ApplicationKeyValue();
        return this;
    }

    public ApplicationKeyValueBuilder withAppKeyValue(String appKeyValue) {
        applicationKeyValue.setAppKeyValue(appKeyValue);
        return this;
    }

    public ApplicationKeyValueBuilder withAppKeyId(Long appKeyId) {
        applicationKeyValue.setAppKeyId(appKeyId);
        return this;
    }

    public ApplicationKeyValueBuilder withDescription(String description) {
        applicationKeyValue.setDescription(description);
        return this;
    }

    public ApplicationKeyValue create() {
        return applicationKeyValue;
    }

    public ApplicationKeyValue saveToDB() {
        applicationKeyValueRepository.save(applicationKeyValue);
        return applicationKeyValue;
    }
}
